<?php
/*
 * @开发工具: JetBrains PhpStorm.
 * @文件名：LoginController.class.php
 * @类功能: 首页
 * @开发者: zc
 * @开发时间： 15-10-22
 * @版本：version 1.0
 */
namespace app\agent\controller;

use app\common\cache\agent\IAgentAdminCache;
use app\common\cache\agent\IAgentCache;
use app\common\cache\agent\IAgentTotalCache;
use app\common\controller\AgentBaseController;
use app\common\enum\IsLeader;
use app\common\ext\IDb;

class Index extends AgentBaseController {

    /**
     * @功能：首页
     * @开发者：cxl
     */
    public function index(){
        //取得管理员信息
        $admin_info = IAgentAdminCache::getInfo(get_login_agent_admin_id());
        if(empty($admin_info['real_name'])){
            $admin_info['real_name'] = $admin_info['phone'];
        }

        //$admin_info['is_leader'] = 2; //测试用代码
//        $brokerage_total = null;
//        $brokerage_all_total = null;
//        if($admin_info['is_leader'] == IsLeader::Yes){
//            //代理商负责人显示全部统计，否则只显示自己的数据
//            $agent_admin_id = null;
//            $admin_info['agent_name'] = IAgentCache::getInfo($admin_info['agent_id'],'agent_name');
//            $brokerage_total = IAgentTotalCache::getAgentBrokerageCountList($admin_info['agent_id']);
//            $brokerage_all_total = IAgentTotalCache::getAgentBrokerageCountAll($admin_info['agent_id']);
//        }
//
//        $where['agent_id'] = $admin_info['agent_id'];
//        $where['agent_admin_id'] = $admin_info['agent_admin_id'];
//
//        $credit_count = IDb::getInstance("credit_apply")->setDbFiled(['sum(if(credit_apply_status=1,1,0 )) as pending','sum(if(credit_apply_status=2,1,0)) as success'])->setDbWhere($where)->row();
//        $loan_count = IDb::getInstance("loan_apply")->setDbFiled(['sum(if(loan_apply_status=1,1,0)) as pending','sum(if(loan_apply_status=2,1,0)) as success'])->setDbWhere($where)->row();
//        $small_count = IDb::getInstance("small_apply")->setDbFiled(['sum(if(small_apply_status=1,1,0)) as pending','sum(if(small_apply_status=2,1,0)) as success'])->setDbWhere($where)->row();

        //设置layout
        $this->layout("layout_menu_one");

        $credit_count = array();
        $loan_count = array();
        $small_count = array();
        $brokerage_total = array();
        $brokerage_all_total = array();
        //获取画面
        $this->assign('admin_info',$admin_info);
        $this->assign('credit_count',$credit_count);
        $this->assign('loan_count',$loan_count);
        $this->assign('small_count',$small_count);
        $this->json('apply',null);
        $this->json('user',null);
        $this->json('brokerage',null);
        $this->json('brokerage_total',$brokerage_total);
        $this->json('brokerage_all',null);
        $this->json('brokerage_all_total',$brokerage_all_total);

        //渲染模板输出
        return view();
    }
}